<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 需求1：
      let arr = []
      for (let i = 0; i < 5; i++) {
        let age = +prompt(`请输入有效年龄`)
        if (age > 0 && age < 100) {
          arr.push(age)
        }
      }
      console.log(arr)
      // 需求2：
      for (let i = 0; i < arr.length; i++) {
        if (arr[i] >= 18) {
          console.log(`所有成年人的年龄为${arr[i]}`)
        }
      }
      // 需求3
      let sum = 0
      for (let i = 0; i < arr.length; i++) {
        sum += arr[i]
      }
      console.log(`所有人总年龄为${sum}`)
      // 需求4
      for (let i = 0; i < arr.length; i++) {
        sum += arr[i]
      }
      console.log(`所有人的平均年龄为${sum / arr.length}`)
      // 需求5
      let max = arr[0]
      for (let i = 0; i < arr.length; i++) {
        if (max < arr[i]) {
          max = arr[i]
        }
      }
      console.log(`最大年龄为${max}`)
      let min = arr[0]
      for (let i = 0; i < arr.length; i++) {
        if (min > arr[i]) {
          min = arr[i]
        }
      }
      console.log(`最小年龄为${min}`)
    </script>
  </body>
</html>
